<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>提交质检单</title>
	    <link rel="stylesheet" href="css/AllStyle.css" />
	    <link rel="stylesheet" href="css/iconfont.css" />
		<link rel="stylesheet" href="css/mui.picker.min.css">
		<link rel="stylesheet" href="css/mui.picker.css">
	    <script type="text/javascript" src="js/common.js" ></script>
	    <script type="text/javascript" src="js/companydata.js" ></script>
	    <script type="text/javascript" src="js/data.js" ></script>
	    <script type="text/javascript" src="js/tmpl.js" ></script>
	</head>
	<body>
		<!-- 页头 -->
	    <section>
		    <script type="text/javascript">
		        AllPageHeader()
		    </script>
	    </section>

	    <!-- 页面  -->
	    <section class="AllContent">
	    	<form>
	    		<div class="FormStyle">
					<ul>
						<li>钢号</li>
						<li>
							<input id="steelSpecification" disabled/>
						</li>

						<li>规格</li>
						<li>
							<input id="standard" disabled/>
						</li>
						<!-- <li>工程编号</li>
						<li>
							<input id="engineCode" disabled/>
						</li> -->
						<li>工程名称</li>
						<li>
							<input id="engineName" disabled/>
						</li>
						<!-- <li>工序代码</li>
						<li>
							<input id="procCode" disabled/>
						</li> -->
						<li>工序名称</li>
						<li>
							<input id="procName" disabled/>
						</li>

						<li>任务单号</li>
						<li>
							<input id="taskNo" disabled/>
						</li>
						<li>任务数量</li>
						<li>
							<input id="taskCount" disabled/>
						</li>
						<li>在制数量</li>
						<li>
							<input id="inProcCount" disabled/>
						</li>
						<li>已报数量</li>
						<li>
							<input id="reportCount" disabled/>
						</li>
						<li>报工数量</li>
						<li>
							<input type="number" id="count" style="width: 220px;" autofocus="autofocus"/>
						</li>
					</ul>
					<div style="text-align: center">
						<button class="reporting NextButton" type="button" style="width: 70%; font-size: 20px; margin: 10px;">提交报工单</button>
					</div>
				</div>
			</form>
		</section>
	</body>

	<script src="js/mui.min.js"></script>
	<script src="js/jquery.min.js"></script>
	<script src="js/common.js"></script>
	<script src="js/data.js"></script>
	<script src="js/mui.picker.js"></script>
	<script src="js/mui.poppicker.js"></script>
	<script type="text/javascript">
		var sData;
		let taskId;
		mui.init();
		$('.AllHeader li:eq(1)').text('提交报工单');
		$('.AllHeader li:eq(2)').html('<img style="width:28px" src="images/Scan.png">')

		mui.plusReady(function(){
			//扫描器
			document.getElementById('Scanner').addEventListener('tap', function() {
				mui.openWindow({
					url: 'Scanner.html?etk=7',
					id:'Scanner.html'
				});
			});
		});

		//添加refresh自定义事件监听
		window.addEventListener('scanReporting',function(){
			var id = event.detail.id;

			mui.ajax(getServerUrl()+"/procedure/proc/findProcByframe", {
				headers: {
					"X-Access-Token": getCookie("token")
				},
				data: {'frameId': id,userName:getCookie("userName")},
				type: 'get',
				dataType: 'json', //从php返回的值以 JSON方式 解释
				contentType: 'application/json',
				timeout: 100000,
				success: function (data) {
					let procList = data.result;
					if (procList===null || procList===undefined || procList.length===0){
						alertMessage("没有查询到此构建可以报工的数据");
						return;
					}
					if (procList.length===1){
						mui.ajax(getServerUrl()+"/task/findByTaskId/",{
							headers:{
								"X-Access-Token":getCookie("token")
							},
							data:{'taskId':procList[0].value},
							type:'get',
							timeout:100000,
							success:function(data){
								$('#taskNo').val(data.taskNo);
								$('#engineName').val(data.engineName);
								$('#procName').val(data.procName);
								$('#taskCount').val(data.taskCount);
								$('#inProcCount').val(data.inProcCount);
								$('#reportCount').val(data.reportCount);
								$('#steelSpecification').val(data.steelSpecification);
								$('#standard').val(data.standard);
								taskId=procList[0].value;
								setTimeout(function(){
									$('#count').focus();
								},1);
							},
							error:function(xhr,type,errorThrown){
							}
						});
					}else {
						var picker = new mui.PopPicker();
						picker.setData(procList);
						picker.show(function (selectItems) {
							mui.ajax(getServerUrl()+"/task/findByTaskId/",{
								headers:{
									"X-Access-Token":getCookie("token")
								},
								data:{'taskId':selectItems[0].value},
								type:'get',
								timeout:100000,
								success:function(data){
									$('#taskNo').val(data.taskNo);
									$('#engineName').val(data.engineName);
									$('#procName').val(data.procName);
									$('#taskCount').val(data.taskCount);
									$('#inProcCount').val(data.inProcCount);
									$('#reportCount').val(data.reportCount);
									$('#steelSpecification').val(data.steelSpecification);
									$('#standard').val(data.standard);
									taskId=selectItems[0].value;
									setTimeout(function(){
										$('#count').focus();
									},1);
								},
								error:function(xhr,type,errorThrown){
								}
							});
						});
					}
				},
				error: function (data) {
					console.log(JSON.stringify(data));
				}
			});
		});

		$(function(){
			if(getCookie("token") === null || getCookie("token") === ''){
				window.location.href='login.html';
				return;
			}
		});
		mui('body').on('tap', '.reporting', function() {
			var inProcCount = $('#inProcCount').val();
			var count = $('#count').val();
			if(count === undefined || count === ''){
				alert("请输入报工数量！");
				return;
			}
			if(parseInt(count) <= 0){
				alert("您输入正确的报工数量！");
				return;
			}
			if(parseInt(inProcCount) < parseInt(count)){
				alert("您输入的报工数量大于在制数量！");
				return;
			}
			$.ajax(getServerUrl()+'/reporting/reporting/report',{
				headers:{
					"X-Access-Token":getCookie("token")
				},
				data:{'taskId':taskId,'reportCount':parseInt(count)},
				type:'post',
				timeout:100000,
				success:function(data){
					$('#taskNo').val('');
					$('#engineName').val('');
					$('#procName').val('');
					$('#taskCount').val('');
					$('#inProcCount').val('');
					$('#reportCount').val('');
					$('#steelSpecification').val('');
					$('#standard').val('');
					$('#count').val('');
					mui.toast("报工成功");

				},
				error:function(xhr,type,errorThrown){
					window.location.href='login.html';
				}
			})
		});
		mui('body').on('tap', '.myFirstPage', function() {
			mui.openWindow({
				url:'supper.html',
				id:'supper.html',
			})
		});
	</script>
<style>
	input{
		background:transparent;
		color:#aaa;
		border:1px solid #aaa;

	}
</style>
</html>
